<?php
namespace app\index\controller;
use think\Controller;
use think\view;
use think\Db;
use think\Input;



class Goods extends Controller {
	
	  //首页
    public function index(){	       
      return $this->fetch();
    }
    
    //LIST
    public function lists(){
      $data=Db::table('goods')->order('name asc')->select();          
      return json($data);
    } 


	 //add
    public function add(){         
      return $this->fetch();
    }
 

    //added
    public function added(){ 
      $data=input('post.');
      $res=Db::table('goods')->insert($data);

      if($res){
        return  '添加成功';
       }
       else
       {
        return  "添加失败"; 
      }
     } 


    //del
    public function del(){ 
      $id=input('get.id');
      $res=Db::table('goods')->where("id",$id)->delete();
      if($res){
        return  '删除成功';
       }
       else
       {
        return  "删除失败"; 
      }
     } 


    //batchdel
    public function batchdel(){ 
     $ids=input('post.ids');
      $res=Db::table('goods')->delete($ids);
      if($res){
        return  '删除成功';
       }
       else
       {
        return  "删除失败"; 
       }
     } 


      //修改
    public function edit(){
       return $this->fetch();      
      }

      //ajax保存修改
    public function editSave(){     
        $data=input('post.');
        $id=input('post.id');
        
        $result=Db::table('goods')->where('id',$id)->update($data);
        if($result){        
             return '修改成功';
        } 
        else
        {
        return '修改失败';  
        }    
      }

   
	
}



